2015年12月8日 | Leave a comment 问题: jms发5000条message,在servlet 中正常,但是在ejb中就不行 for(int i=0;i<5000;++i){ LOG.info("send "+i); p.send(queue1, "msg i:"+i); } 1234 for(int i=0;i<5000;++i){ LOG.info("send "+i); p.send(queue1, "msg i:"+i); } EJB中报错: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. 1 The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. 警告: StandardWrapperValve[Servlet1]: Servlet.service() for servlet Servlet1 threw exception javax.ejb.EJBException at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752) at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702) at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507) at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) at com.sun.proxy.$Proxy437.batchSend(Unknown Source) at me.yek.jms2.__EJB31_Generated__UserService__Intf____Bean__.batchSend(Unknown Source) at me.yek.jms2.Servlet1.processRequest(Servlet1.java:59) at me.yek.jms2.Servlet1.doGet(Servlet1.java:87) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) at java.lang.Thread.run(Thread.java:745) Caused by: com.sun.messaging.jms.MQRuntimeException: MQJMSRA_DS4001: JMSServiceException on send message:sendMessage: Sending message failed. Connection ID: 7390215127550394880 Caused by:com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jmq.jmsclient.JMSProducerImpl.send(JMSProducerImpl.java:161) at me.yek.jms2.UserService.batchSend(UserService.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081) at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153) at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786) at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64) at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52) at sun.reflect.GeneratedMethodAccessor1048.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140) at sun.reflect.GeneratedMethodAccessor1416.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369) at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758) at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212) ... 35 more Caused by: javax.jms.JMSException: MQJMSRA_DS4001: JMSServiceException on send message:sendMessage: Sending message failed. Connection ID: 7390215127550394880 Caused by:com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jms.ra.DirectSession._sendMessage(DirectSession.java:1995) at com.sun.messaging.jms.ra.DirectProducer._send(DirectProducer.java:1138) at com.sun.messaging.jms.ra.DirectProducer.send(DirectProducer.java:394) at com.sun.messaging.jmq.jmsclient.JMSProducerImpl.send(JMSProducerImpl.java:152) ... 65 more Caused by: com.sun.messaging.jmq.jmsservice.JMSServiceException: sendMessage: Sending message failed. Connection ID: 7390215127550394880 Caused by:com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jmq.jmsserver.service.imq.JMSServiceImpl.sendMessage(JMSServiceImpl.java:1848) at com.sun.messaging.jms.ra.DirectSession._sendMessage(DirectSession.java:1990) ... 68 more Caused by: com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jmq.jmsserver.data.handlers.DataHandler.routeMessage(DataHandler.java:511) at com.sun.messaging.jmq.jmsserver.data.protocol.ProtocolImpl.processMessage(ProtocolImpl.java:1130) at com.sun.messaging.jmq.jmsserver.service.imq.JMSServiceImpl.sendMessage(JMSServiceImpl.java:1841) ... 69 more 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 警告: StandardWrapperValve[Servlet1]: Servlet.service() for servlet Servlet1 threw exceptionjavax.ejb.EJBException at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752) at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702) at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507) at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) at com.sun.proxy.$Proxy437.batchSend(Unknown Source) at me.yek.jms2.__EJB31_Generated__UserService__Intf____Bean__.batchSend(Unknown Source) at me.yek.jms2.Servlet1.processRequest(Servlet1.java:59) at me.yek.jms2.Servlet1.doGet(Servlet1.java:87) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) at java.lang.Thread.run(Thread.java:745)Caused by: com.sun.messaging.jms.MQRuntimeException: MQJMSRA_DS4001: JMSServiceException on send message:sendMessage: Sending message failed. Connection ID: 7390215127550394880 Caused by:com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jmq.jmsclient.JMSProducerImpl.send(JMSProducerImpl.java:161) at me.yek.jms2.UserService.batchSend(UserService.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081) at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153) at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786) at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64) at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52) at sun.reflect.GeneratedMethodAccessor1048.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163) at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140) at sun.reflect.GeneratedMethodAccessor1416.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369) at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758) at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212) ... 35 moreCaused by: javax.jms.JMSException: MQJMSRA_DS4001: JMSServiceException on send message:sendMessage: Sending message failed. Connection ID: 7390215127550394880 Caused by:com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jms.ra.DirectSession._sendMessage(DirectSession.java:1995) at com.sun.messaging.jms.ra.DirectProducer._send(DirectProducer.java:1138) at com.sun.messaging.jms.ra.DirectProducer.send(DirectProducer.java:394) at com.sun.messaging.jmq.jmsclient.JMSProducerImpl.send(JMSProducerImpl.java:152) ... 65 moreCaused by: com.sun.messaging.jmq.jmsservice.JMSServiceException: sendMessage: Sending message failed. Connection ID: 7390215127550394880 Caused by:com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jmq.jmsserver.service.imq.JMSServiceImpl.sendMessage(JMSServiceImpl.java:1848) at com.sun.messaging.jms.ra.DirectSession._sendMessage(DirectSession.java:1990) ... 68 moreCaused by: com.sun.messaging.jmq.jmsserver.util.BrokerException: [B4403]: Exception on processing produced message PacketReference[83402-192.168.31.232(91:a4:51:6d:9e:3f)-1-1449568517940][TID=7390215128102122496, null]: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=7390215128102122496) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property. at com.sun.messaging.jmq.jmsserver.data.handlers.DataHandler.routeMessage(DataHandler.java:511) at com.sun.messaging.jmq.jmsserver.data.protocol.ProtocolImpl.processMessage(ProtocolImpl.java:1130) at com.sun.messaging.jmq.jmsserver.service.imq.JMSServiceImpl.sendMessage(JMSServiceImpl.java:1841) ... 69 more 解决: EJB method 设置禁止Transactional @Transactional(value=TxType.NOT_SUPPORTED) 1 @Transactional(value=TxType.NOT_SUPPORTED) package me.yek.jms2; import javax.annotation.Resource; import javax.ejb.Singleton; import javax.ejb.LocalBean; import javax.inject.Inject; import javax.jms.JMSConnectionFactory; import javax.jms.JMSContext; import javax.jms.Queue; import javax.transaction.Transactional; import javax.transaction.Transactional.TxType; /** * * @author sihai */ @Singleton @LocalBean public class UserService { @Resource(mappedName = "jms/queue1") private Queue queue1; @Inject @JMSConnectionFactory("java:comp/DefaultJMSConnectionFactory") private JMSContext context; // Add business logic below. (Right-click in editor and choose // "Insert Code > Add Business Method") public void send(String msg){ context.createProducer().send(queue1, msg); } @Transactional(value=TxType.NOT_SUPPORTED) public void batchSend(){ for(int i=0;i<5000;++i){ context.createProducer().send(queue1, "batch msg "+i); } } } 12345678910111213141516171819202122232425262728293031323334353637383940 package me.yek.jms2; import javax.annotation.Resource;import javax.ejb.Singleton;import javax.ejb.LocalBean;import javax.inject.Inject;import javax.jms.JMSConnectionFactory;import javax.jms.JMSContext;import javax.jms.Queue;import javax.transaction.Transactional;import javax.transaction.Transactional.TxType; /** * * @author sihai */@Singleton@LocalBeanpublic class UserService { @Resource(mappedName = "jms/queue1") private Queue queue1; @Inject @JMSConnectionFactory("java:comp/DefaultJMSConnectionFactory") private JMSContext context; // Add business logic below. (Right-click in editor and choose // "Insert Code > Add Business Method") public void send(String msg){ context.createProducer().send(queue1, msg); } @Transactional(value=TxType.NOT_SUPPORTED) public void batchSend(){ for(int i=0;i<5000;++i){ context.createProducer().send(queue1, "batch msg "+i); } }} update: EJB 方法是会默认有transaction require 的,所以在ejb 方法循环发送消息都会放到一个transaction中,需要把方法标注为 @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) 以禁止Transaction,还没搞透,有时需要标注caller 方法